package com.itbaiyun.usercenter.once;
import java.util.Date;

import com.itbaiyun.usercenter.mapper.UserMapper;
import com.itbaiyun.usercenter.model.domain.User;
import com.itbaiyun.usercenter.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import javax.annotation.Resource;

@Component
@Slf4j
public class InsertUsers {
    @Resource
    private UserMapper userMapper;

//    @Scheduled(initialDelay = 5000,fixedRate = Long.MAX_VALUE)
    public void doInsertUsers(){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        final int INSERT_COUNT = 1000;
        for (int i = 0; i < INSERT_COUNT; i++) {
            User user = new User();
            user.setIsDelete(0);
            user.setUpdateTime(new Date());
            user.setCreateTime(new Date());
            user.setUserStatus(0);
            user.setEmail("123@qq.com");
            user.setPhone("135xxxxxxxx");
            user.setUserPassword("12345678");
            user.setTags("[]");
            user.setGender(0);
            user.setAvatarUrl("https://ts1.cn.mm.bing.net/th/id/R-C.f696c70eea53bd54e91fff5b65d8d06a?rik=2mBjOKN3%2b0pYag&riu=http%3a%2f%2fimg.touxiangwu.com%2f2020%2f3%2f3QRfqa.jpg&ehk=263ZRDleUxN%2fG6wux14UWLQ7Vp5%2fd2KdU5l1bTUhHJc%3d&risl=&pid=ImgRaw&r=0");
            user.setUserAccount("");
            user.setUsername("大帅哥");
            user.setUserRole(0);
            user.setPlanetCode("111");
            userMapper.insert(user);
        }
        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeSeconds());
        //7.332秒
    }
}

